OptTreeCtl = Ext.extend(CmpControler, {

			bulidComponent : function() {

				var config = this.getCommonConfig();

				var item = new Ext.tree.TreePanel(config);

				var root = this.getTreeNodes();

				item.setRootNode(root);

				return item;
			},
			expandChildNodes : function() {
				var cmp = this.cmp;
				var root = cmp.getRootNode();
				root.expand();
			},
			getCommonConfig : function() {
				
				var gcc = cf.getC('gcc');
				var config = {
					border : false,
					region : 'west',
					split : true,
					autoScroll : true,
					useArrows : true,
					frame : true,
					// animate : true,
					width : gcc.sw * 0.2
				}

				return config;
			},
			getTreeNodes : function() {

				var root = new Ext.tree.TreeNode({
							text : '系统功能'
						});

				this.appendSysNode(root);

				this.appendWorkNode(root);

				return root;

			},
			appendSysNode : function(root) {

				var nodeSys = this.createNode('系统管理', 'sn');

				this.appendUserMgrNode(nodeSys);
				// this.appendSysSearchNode(nodeSys);

				root.appendChild(nodeSys);

			},
			appendSysSearchNode : function(root) {

				var node = this.createNode('系统查询', 'ssn');

				node.appendChild(this.createNode('用户日志', 'uln'));

				root.appendChild(node);

			},
			appendUserMgrNode : function(root) {

				var node = this.createNode('用户管理', 'umn');

				var gcc = cf.getC('gcc');
				if (gcc.user.permissions.usermgr_read) {
					node.appendChild(this.createNode('用户信息管理', 'usrmger'));
				}
				if (gcc.user.permissions.userpasswordmgr_edit) {
					node.appendChild(this.createNode('更改密码', 'uofc'));
				}

				if (node.hasChildNodes) {
					root.appendChild(node);
				}

			},
			appendWorkNode : function(root) {

				var workNode = this.createNode('工作区', 'wn');

				this.appendCustomerMgrNode(workNode);
				// this.appendProjectMgrNode(workNode);
				this.appendAgreementMgrNode(workNode);

				this.appendOrderMgrNode(workNode);
				this.appendWorkTicketNode(workNode);
				this.appendFinishNode(workNode);
				
				this.appendBillsNode(workNode);

				if (workNode.hasChildNodes) {
					root.appendChild(workNode);
				}

			},
			appendBillsNode : function(root) {

				var node = this.createNode('账单', 'b');

				var gcc = cf.getC('gcc');
				//if (gcc.user.permissions.bills_read) {

					node.appendChild(this.createNode('账单管理', 'billManagerPanel'));

				//}
				if (node.hasChildNodes()) {
					root.appendChild(node);
				}

			},
			appendFinishNode : function(root) {

				var node = this.createNode('交付单', 'f');

				var gcc = cf.getC('gcc');
				if (gcc.user.permissions.finishmgr_read) {

					node.appendChild(this.createNode('交付单审核', 'fgc'));

				}
				if (node.hasChildNodes()) {
					root.appendChild(node);
				}

			},
			appendWorkTicketNode : function(root) {

				var node = this.createNode('工作单', 'wtn');

				var gcc = cf.getC('gcc');
				if (gcc.user.permissions.workmgr_read) {

					node.appendChild(this.createNode('工作单查看', 'wgc'));

				}

				if (node.hasChildNodes()) {
					root.appendChild(node);
				}

			},
			appendOrderMgrNode : function(root) {

				var node = this.createNode('订单', 'order');

				var gcc = cf.getC('gcc')
				if (gcc.user.permissions.ordermgr_read) {

					node.appendChild(this.createNode('订单建立', 'opc'));

				}

				if (gcc.user.permissions.orderaudit_read) {

					node.appendChild(this.createNode('订单审核', 'oagc'));

				}

				if (node.hasChildNodes()) {
					root.appendChild(node);
				}

			},
			appendAgreementMgrNode : function(root) {

				var node = this.createNode('协议管理', 'amn');
				var gcc = cf.getC('gcc')
				if (gcc.user.permissions.contractmgr_read) {

					node.appendChild(this.createNode('协议单信息管理', 'aigc'));

				}

				if (gcc.user.permissions.contractaudit_read) {

					node.appendChild(this.createNode('协议单审核', 'aagc'));

				}

				if (node.hasChildNodes()) {
					root.appendChild(node);
				}

			},
			appendCustomerMgrNode : function(root) {

				var node = this.createNode('客户管理', 'cmn');

				var gcc = cf.getC('gcc')
				if (gcc.user.permissions.customermgr_read) {

					node.appendChild(this.createNode('客户信息管理', 'cpc'));

				}

				if (gcc.user.permissions.customerconflict_read) {

					node.appendChild(this.createNode('客户冲突查询', 'ccpc'));

				}

				if (gcc.user.permissions.customeraudit_read) {

					node.appendChild(this.createNode('客户审核', 'cagc'));

				}

				if (node.hasChildNodes()) {
					root.appendChild(node);
				}

			},
			createNode : function(text, id) {

				var node = new Ext.tree.TreeNode({
							id : id,
							singleClickExpand : true,
							text : text
						});

				node.on('click', this.nodeClick, this);

				return node;

			},
			nodeClick : function(node) {
				var rpc = cf.getC('rpc');
				rpc.active(node);
			}

		});
